package cn.stylefeng.guns.modular.third.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.third.entity.ThirdManagementStatistics;
import cn.stylefeng.guns.modular.third.mapper.ThirdManagementStatisticsMapper;
import cn.stylefeng.guns.modular.third.model.params.ThirdManagementStatisticsParam;
import cn.stylefeng.guns.modular.third.model.result.ThirdManagementStatisticsResult;
import  cn.stylefeng.guns.modular.third.service.ThirdManagementStatisticsService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 运输管理统计 服务实现类
 */
@Service
public class ThirdManagementStatisticsServiceImpl extends ServiceImpl<ThirdManagementStatisticsMapper, ThirdManagementStatistics> implements ThirdManagementStatisticsService {

    @Override
    public void add(ThirdManagementStatisticsParam param){
        ThirdManagementStatistics entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ThirdManagementStatisticsParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ThirdManagementStatisticsParam param){
        ThirdManagementStatistics oldEntity = getOldEntity(param);
        ThirdManagementStatistics newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ThirdManagementStatisticsResult findBySpec(ThirdManagementStatisticsParam param){
        return null;
    }

    @Override
    public List<ThirdManagementStatisticsResult> findListBySpec(ThirdManagementStatisticsParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ThirdManagementStatisticsParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ThirdManagementStatisticsParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ThirdManagementStatistics getOldEntity(ThirdManagementStatisticsParam param) {
        return this.getById(getKey(param));
    }

    private ThirdManagementStatistics getEntity(ThirdManagementStatisticsParam param) {
        ThirdManagementStatistics entity = new ThirdManagementStatistics();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public int countBydate(ThirdManagementStatisticsParam param) {
		Integer a;
		a = this.baseMapper.countBydate(param);
		if (a == null) {
			return 0;
		}
		return a;
	}

}
